home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / manage / snmp / kip / inet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-17  |  7.3 KB  |  269 lines

  1. /*
  2.  *  (c) 1984, Stanford Univ. SUMEX project.
  3.  *  May be used but not sold without permission.
  4.  *
  5.  *  (c) 1986, Kinetics, Inc.
  6.  *  May be used but not sold without permission.
  7.  *
  8.  *  $Header: inet.h,v 4.1 88/11/01 19:49:53 sw0l Exp $
  9.  */
  10.  
  11. /*
  12.  * Constants and structures defined by the internet system,
  13.  * Per RFC 790, September 1981.
  14.  */
  15.  
  16. /*
  17.  * Protocols
  18.  */
  19. #define    IPPROTO_ICMP        1        /* control message protocol */
  20. #define    IPPROTO_GGP        2        /* gateway^2 (deprecated) */
  21. #define    IPPROTO_TCP        6        /* tcp */
  22. #define    IPPROTO_PUP        12        /* pup */
  23. #define    IPPROTO_UDP        17        /* user datagram protocol */
  24. #define    IPPROTO_ND        77        /* UNOFFICIAL net disk proto */
  25.  
  26. #define    IPPROTO_RAW        255        /* raw IP packet */
  27. #define    IPPROTO_MAX        256
  28.  
  29. /*
  30.  * Port/socket numbers: network standard functions
  31.  */
  32. #define    IPPORT_ECHO        7
  33. #define    IPPORT_DISCARD        9
  34. #define    IPPORT_SYSTAT        11
  35. #define    IPPORT_DAYTIME        13
  36. #define    IPPORT_NETSTAT        15
  37. #define    IPPORT_FTP        21
  38. #define    IPPORT_TELNET        23
  39. #define    IPPORT_SMTP        25
  40. #define    IPPORT_TIMESERVER    37
  41. #define    IPPORT_NAMESERVER    42
  42. #define    IPPORT_WHOIS        43
  43. #define    IPPORT_MTP        57
  44.  
  45. /*
  46.  * Port/socket numbers: host specific functions
  47.  */
  48. #define    IPPORT_TFTP        69
  49. #define    IPPORT_RJE        77
  50. #define    IPPORT_FINGER        79
  51. #define    IPPORT_TTYLINK        87
  52. #define    IPPORT_SUPDUP        95
  53.  
  54. /*
  55.  * UNIX TCP sockets
  56.  */
  57. #define    IPPORT_EXECSERVER    512
  58. #define    IPPORT_LOGINSERVER    513
  59. #define    IPPORT_CMDSERVER    514
  60. #define    IPPORT_EFSSERVER    520
  61.  
  62. /*
  63.  * UNIX UDP sockets
  64.  */
  65. #define    IPPORT_BIFFUDP        512
  66. #define    IPPORT_WHOSERVER    513
  67. #define    IPPORT_ROUTESERVER    520    /* 520+1 also used */
  68.  
  69. /*
  70.  * Ports < IPPORT_RESERVED are reserved for
  71.  * privileged processes (e.g. root).
  72.  */
  73. #define    IPPORT_RESERVED        1024
  74.  
  75. /*
  76.  * Link numbers
  77.  */
  78. #define    IMPLINK_IP        155
  79. #define    IMPLINK_LOWEXPER    156
  80. #define    IMPLINK_HIGHEXPER    158
  81.  
  82.  
  83. /*
  84.  * Definitions of bits in internet address integers.
  85.  */
  86. #define    IN_CLASSA(i)        ((((long)(i))&0x80000000)==0)
  87. #define    IN_CLASSA_NET        0xff000000
  88. #define    IN_CLASSA_NSHIFT    24
  89. #define    IN_CLASSA_HOST        0x00ffffff
  90.  
  91. #define    IN_CLASSB(i)        ((((long)(i))&0xc0000000)==0x80000000)
  92. #define    IN_CLASSB_NET        0xffff0000
  93. #define    IN_CLASSB_NSHIFT    16
  94. #define    IN_CLASSB_HOST        0x0000ffff
  95.  
  96. #define    IN_CLASSC(i)        ((((long)(i))&0xc0000000)==0xc0000000)
  97. #define    IN_CLASSC_NET        0xffffff00
  98. #define    IN_CLASSC_NSHIFT    8
  99. #define    IN_CLASSC_HOST        0x000000ff
  100.  
  101. #define    INADDR_ANY    0x00000000
  102. #define    INADDR_BROADCAST    0xFFFFFFFF
  103.  
  104. /*
  105.  * Definitions for internet protocol version 4.
  106.  * Per RFC 791, September 1981.
  107.  */
  108. #define    IPVERSION    4
  109.  
  110. /*
  111.  * Structure of an internet header, naked of options.
  112.  *
  113.  * We declare ip_len and ip_off to be short, rather than u_short
  114.  * pragmatically since otherwise unsigned comparisons can result
  115.  * against negative integers quite easily, and fail in subtle ways.
  116.  */
  117. struct ip {
  118. #ifdef    lowendian
  119.     u_char    ip_hl:4,        /* header length */
  120.         ip_v:4;            /* version */
  121. #else    lowendian
  122.     u_char    ip_v:4,            /* version */
  123.         ip_hl:4;        /* header length */
  124. #endif    lowendian
  125.     u_char    ip_tos;            /* type of service */
  126.     short    ip_len;            /* total length */
  127.     u_short    ip_id;            /* identification */
  128.     short    ip_off;            /* fragment offset field */
  129. #define    IP_DF 0x4000            /* dont fragment flag */
  130. #define    IP_MF 0x2000            /* more fragments flag */
  131.     u_char    ip_ttl;            /* time to live */
  132.     u_char    ip_p;            /* protocol */
  133.     u_short    ip_sum;            /* checksum */
  134.     iaddr_t    ip_src,ip_dst;        /* source and dest address */
  135. };
  136.  
  137. /*
  138.  * Definitions for options.
  139.  */
  140. #define    IPOPT_COPIED(o)        ((o)&0x80)
  141. #define    IPOPT_CLASS(o)        ((o)&0x60)
  142. #define    IPOPT_NUMBER(o)        ((o)&0x1f)
  143.  
  144. #define    IPOPT_CONTROL        0x00
  145. #define    IPOPT_RESERVED1        0x20
  146. #define    IPOPT_DEBMEAS        0x40
  147. #define    IPOPT_RESERVED2        0x60
  148.  
  149. #define    IPOPT_EOL        0        /* end of option list */
  150. #define    IPOPT_NOP        1        /* no operation */
  151.  
  152. #define    IPOPT_RR        7        /* record packet route */
  153. #define    IPOPT_TS        68        /* timestamp */
  154. #define    IPOPT_SECURITY        130        /* provide s,c,h,tcc */
  155. #define    IPOPT_LSRR        131        /* loose source route */
  156. #define    IPOPT_SATID        136        /* satnet id */
  157. #define    IPOPT_SSRR        137        /* strict source route */
  158.  
  159.  
  160. /*
  161.  * Internet implementation parameters.
  162.  */
  163. #define    MAXTTL        255        /* maximum time to live (seconds) */
  164. #define    IPFRAGTTL    15        /* time to live for frag chains */
  165. #define    IPTTLDEC    1        /* subtracted when forwarding */
  166.  
  167.  
  168. /*
  169.  * Interface Control Message Protocol Definitions.
  170.  * Per RFC 792, September 1981.
  171.  */
  172.  
  173. /*
  174.  * Structure of an icmp header.
  175.  */
  176. struct icmp {
  177.     u_char    icmp_type;        /* type of message, see below */
  178.     u_char    icmp_code;        /* type sub code */
  179.     u_short    icmp_cksum;        /* ones complement cksum of struct */
  180.     union {
  181.         u_char ih_pptr;            /* ICMP_PARAMPROB */
  182.         iaddr_t ih_gwaddr;        /* ICMP_REDIRECT */
  183.         struct ih_idseq {
  184.             n_short    icd_id;
  185.             n_short    icd_seq;
  186.         } ih_idseq;
  187.         int ih_void;
  188.     } icmp_hun;
  189. #define    icmp_pptr    icmp_hun.ih_pptr
  190. #define    icmp_gwaddr    icmp_hun.ih_gwaddr
  191. #define    icmp_id        icmp_hun.ih_idseq.icd_id
  192. #define    icmp_seq    icmp_hun.ih_idseq.icd_seq
  193. #define    icmp_void    icmp_hun.ih_void
  194.     union {
  195.         struct id_ts {
  196.             n_time its_otime;
  197.             n_time its_rtime;
  198.             n_time its_ttime;
  199.         } id_ts;
  200.         struct id_ip  {
  201.             struct ip idi_ip;
  202.             /* options and then 64 bits of data */
  203.         } id_ip;
  204.     } icmp_dun;
  205. #define    icmp_otime    icmp_dun.id_ts.its_otime
  206. #define    icmp_rtime    icmp_dun.id_ts.its_rtime
  207. #define    icmp_ttime    icmp_dun.id_ts.its_ttime
  208. #define    icmp_ip        icmp_dun.id_ip.idi_ip
  209. };
  210.  
  211. /*
  212.  * Lower bounds on packet lengths for various types.
  213.  * For the error advice packets must first insure that the
  214.  * packet is large enought to contain the returned ip header.
  215.  * Only then can we do the check to see if 64 bits of packet
  216.  * data have been returned, since we need to check the returned
  217.  * ip header length.
  218.  */
  219. #define    ICMP_MINLEN    8                /* abs minimum */
  220. #define    ICMP_TSLEN    (8 + 3 * sizeof (n_time))    /* timestamp */
  221. #define    ICMP_ADVLENMIN    (8 + sizeof (struct ip) + 8)    /* min */
  222. #define    ICMP_ADVLEN(p)    (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
  223.     /* N.B.: must separately check that ip_hl >= 5 */
  224.  
  225. /*
  226.  * Definition of type and code field values.
  227.  */
  228. #define    ICMP_ECHOREPLY        0        /* echo reply */
  229. #define    ICMP_UNREACH        3        /* dest unreachable, codes: */
  230. #define        ICMP_UNREACH_NET    0        /* bad net */
  231. #define        ICMP_UNREACH_HOST    1        /* bad host */
  232. #define        ICMP_UNREACH_PROTOCOL    2        /* bad protocol */
  233. #define        ICMP_UNREACH_PORT    3        /* bad port */
  234. #define        ICMP_UNREACH_NEEDFRAG    4        /* IP_DF caused drop */
  235. #define        ICMP_UNREACH_SRCFAIL    5        /* src route failed */
  236. #define    ICMP_SOURCEQUENCH    4        /* packet lost, slow down */
  237. #define    ICMP_REDIRECT        5        /* shorter route, codes: */
  238. #define        ICMP_REDIRECT_NET    0        /* for network */
  239. #define        ICMP_REDIRECT_HOST    1        /* for host */
  240. #define        ICMP_REDIR_TOSNET    2        /* for tos and net */
  241. #define        ICMP_REDIRECT_TOSHOST    3        /* for tos and host */
  242. #define    ICMP_ECHO        8        /* echo service */
  243. #define    ICMP_TIMXCEED        11        /* time exceeded, code: */
  244. #define        ICMP_TIMXCEED_INTRANS    0        /* ttl==0 in transit */
  245. #define        ICMP_TIMXCEED_REASS    1        /* ttl==0 in reass */
  246. #define    ICMP_PARAMPROB        12        /* ip header bad */
  247. #define    ICMP_TSTAMP        13        /* timestamp request */
  248. #define    ICMP_TSTAMPREPLY    14        /* timestamp reply */
  249. #define    ICMP_IREQ        15        /* information request */
  250. #define    ICMP_IREQREPLY        16        /* information reply */
  251. #define    ICMP_AFREQ        17        /* address format request */
  252. #define    ICMP_AFREPLY        18        /* address format reply */
  253.  
  254.     /* highest known ICMP type code */
  255. #define    ICMP_MAXTYPE        18
  256.  
  257.  
  258. /*
  259.  * Udp protocol header.
  260.  * Per RFC 768, September, 1981.
  261.  */
  262. struct udp {
  263.     u_short    src;            /* source port */
  264.     u_short    dst;            /* destination port */
  265.     short    length;            /* udp length */
  266.     u_short    checksum;        /* udp checksum */
  267. };
  268.  
  269.